<template>
    <div>
        <h1>新闻详情页{{news_id}}</h1>
        <div>
            <p>新闻内容：{{news_info.content}}</p>
            <p>点赞次数：{{news_info.stars}}</p>
            <p>所属分类：{{news_info.cate}}</p>
        </div>
        <button @click="dianzan">点赞</button>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            news_id:this.$route.query.news_id,
            base_url:'http://127.0.0.1:8000',
            news_info:{},
        }
    },
    methods: {
        dianzan() {
            let fdata=new FormData()
            fdata.append('news_id',this.news_id)
            if(sessionStorage.getItem('user_id')) {
            
            axios({
                url:this.base_url+'/app01/news_stars/',
                method:'post',
                data:fdata
            }).then(resp=>{
                console.log(resp.data)
                this.get_newinfo()
            })
            }else{
                this.$router.push({path:'/login'})
            }
        },
        get_newinfo() {
                axios({
                url:this.base_url+'/app01/news_info/',
                method:'get',
                params:{'news_id':this.news_id}
            }).then(resp=>{
                console.log(resp.data)
                this.news_info=resp.data
            })
        },
    },
    created() {
        this.get_newinfo()
    }
}
</script>

<style scoped>

</style>
